import _ from 'lodash';

export default class HttpHelper {
  static filedMixedToPlural = <T>(filed: T | Array<T> | undefined): Array<T> => {
    if (!filed) {
      return [];
    }
    if (_.isArray(filed)) {
      return [...filed];
    }
    return [filed];
  };

  static filedMixedToSingular = <T>(filed: T | Array<T> | undefined): T | undefined => {
    if (_.isArray(filed)) {
      return filed[0];
    }
    return filed;
  };

  static isHeaderValueTrue = (feiled: string | string[] | undefined): boolean => {
    return HttpHelper.filedMixedToSingular(feiled) === 'true';
  };
}
